﻿package com.wandian.view.mediator
{
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.controller.RankCommand;
	import com.wandian.data.GameData;
	import com.wandian.model.UserInfoProxy;
	import com.wandian.model.socket.net.Command;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZButtonFour;
	import com.wandian.util.CLZListRank;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadingData;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZTiming;
	import com.wandian.util.RadioRoom;
	import com.wandian.view.components.ui.RoomInfo;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

    public class RankMediator extends Mediator
    {
        private var _mcCotent:Sprite;
        private var _clzList:CLZListRank;
        private var _arrRank:Array;
        private var _recordType:int;
        public static const NAME:String = "RankMediator";

        public function RankMediator(param1:Object = null)
        {
            super(NAME, param1);
            return;
        }

        private function init() : void
        {
            facade.registerCommand(CLZNoticeName.RANK_TOP_REQ, RankCommand);
            this._mcCotent = new Sprite();
            this.mcRank.addChild(this._mcCotent);
            this._mcCotent.x = 50;
            this._mcCotent.y = 58;
            this._clzList = new CLZListRank(this._mcCotent, "InfoMc", this.mcRank.prevBtn, this.mcRank.nextBtn, this.mcRank.fristBtn, this.mcRank.endBtn);
            CLZButton.setButton(this.mcRank.btn_addFriend, GameData.tip["INVITATION_FRIEND"]);
            this.mcRank.btn_addFriend.addEventListener(MouseEvent.CLICK, this.onInvitationFunc);
            var _loc_1:Array = [[this.mcRank.gold_btn, GameData.tip["WEALTH_NAME"]], [this.mcRank.friend_btn, GameData.tip["FRIEND_NAME"]], [this.mcRank.win_btn, GameData.tip["WIN_NAME"]]];
            var _loc_2:* = new CLZTabBar(_loc_1);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_1[_loc_3][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
                _loc_3 = _loc_3 + 1;
            }
            _loc_2.setClickIndex(this.mcRank.gold_btn);
            return;
        }

        private function onInvitationFunc(event:MouseEvent) : void
        {
//            JSFUN.shareInvitationFunc();
            return;
        }

        private function removeAll() : void
        {
            GameData.removeNumChildre(this._mcCotent);
            return;
        }

        private function changeTabBarHandler(event:Event) : void
        {
            var _loc_2:UserInfoProxy = null;
            var _loc_3:Array = null;
            switch(event.target.name)
            {
                case "gold_btn":
                {
                    this._recordType = 1;
                    CLZLoadingData.show(this.mcRank);
                    this.sendNotification(CLZNoticeName.RANK_TOP_REQ, this._recordType);
                    break;
                }
                case "friend_btn":
                {
                    this._recordType = 3;
                    _loc_2 = facade.retrieveProxy(UserInfoProxy.NAME) as UserInfoProxy;
                    _loc_3 = GameData.sortMaxToMinArray(_loc_2.arrFriend, "gold");
                    this.showList(_loc_3, this._recordType);
                    break;
                }
                case "win_btn":
                {
                    this._recordType = 2;
                    CLZLoadingData.show(this.mcRank);
                    this.sendNotification(CLZNoticeName.RANK_TOP_REQ, this._recordType);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function showList(param1:Array, param2:int) : void
        {
            this._clzList.setList(param1, param2);
            return;
        }

        override public function onRegister() : void
        {
            this.init();
            return;
        }

        override public function listNotificationInterests() : Array
        {
            return [CLZNoticeName.RANK_TOP_RES];
        }

        override public function handleNotification(param1:INotification) : void
        {
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            switch(param1.getName())
            {
                case CLZNoticeName.RANK_TOP_RES:
                {
                    this.removeAll();
                    CLZLoadingData.hide(this.mcRank);
                    _loc_2 = param1.getBody();
                    this._arrRank = _loc_2.arr;
                    _loc_3 = _loc_2.type;
                    if (this._recordType == _loc_3)
                    {
                        this.showList(this._arrRank, _loc_3);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function get mcRank() : MovieClip
        {
            return viewComponent as MovieClip;
        }

    }
}
